package com.xinzhuoyue.erp.controller;


import com.xinzhuoyue.erp.model.User;
import com.xinzhuoyue.erp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

@Controller
@RequestMapping("/user")
@SessionAttributes("username")
public class UserController {
	private UserService userService;

	public UserService getUserService() {

		return userService;
	}

	@Autowired
	public void setUserService(UserService userService) {

		this.userService = userService;
	}

	@PostMapping("/userLogin")
	public String login(int id, Model model) {
		User u= this.getUserService().UserLogin(id);
		if (u != null) {
			model.addAttribute("user", u);
			return "test";
		} else {
			return "index";
		}
	}
}
